<template>
  <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
      <FormItem label="姓名" prop="name">
        <Input v-model="formValidate.name" placeholder="请输入姓名"></Input>
      </FormItem>
    <FormItem label="账号" prop="username">
      <Input v-model="formValidate.username" placeholder="请输入账号"></Input>
    </FormItem>
    <FormItem label="密码" prop="password">
        <Input v-model="formValidate.password" type="password" placeholder="密码"></Input>
      </FormItem>
      <FormItem>
        <Button type="primary" @click="handleSubmit('formValidate')">Submit</Button>
        <Button @click="handleReset('formValidate')" style="margin-left: 8px">Reset</Button>
      </FormItem>
    </Form>
</template>

<script>
import { save } from '@/api/user/save'
export default {
  name: 'user_add',
  data () {
    return {
      content: '',
      types: [],
      formValidate: {
        userId: '',
        name: '',
        username: '',
        password: ''
      },
      ruleValidate: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        username: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleSubmit (name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          save(this.formValidate).then(res => {
            this.$Message.success('提交成功!')
          })
        } else {
          this.$Message.error('提交失败!')
        }
      })
    },
    handleReset (name) {
      this.$refs[name].resetFields()
    }
  },
  mounted () {
  }
}
</script>

<style>

</style>
